<?php

!defined('IN_TIPASK') && exit('Access Denied');

class admin_expertcontrol extends base {

    function admin_expertcontrol(& $get, & $post) {
        $this->base(& $get, & $post);
        $this->load('expert');
        $this->load('user');
        $this->load('category');
    }

    function ondefault($msg='') {
        $expertlist  = $_ENV['expert']->get_list(0,100);
        $msg && $message=$msg;
        include template('expertlist', 'admin');
    }

    function onadd() {
        //Array ( [admin_expert/add_html] => [username] => s [goodatcategory] => s )
        $type = 'correctmsg';
        $message = '';
        $categorylist = explode(",",$this->post['goodatcategory']);
        $username = $this->post['username'];
        $user = $_ENV['user']->get_by_username($username);

        if (!$user) {
            $type = 'errormsg';
            $message = "用户名 [$username] 不存在";
        }

        if($_ENV['expert']->get_by_username($username)){
            $type='errormsg';
            $message.= "用户[$username]已经是专家了";

        }


        if (count($categorylist) > 3) {
            $type = 'errormsg';
            $message .= "<br />擅长分类不能超过3个";
        }
        //添加专家
        if('correctmsg' == $type){
            $_ENV['expert']->add($user['uid'],$user['username'], $this->post['goodatcategory']);
            
        }
       $this->ondefault($message);
    }

    function onremove(){
       if(count($this->post['delete'])){
           $_ENV['expert']->remove(implode(',',$this->post['delete']));
           $type='correctmsg';
           $message = "删除成功！";
           $this->ondefault($message);
       }
    }

}

?>